<%@ page import="com.google.appengine.api.blobstore.BlobKey" %>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreService" %>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory" %>
<%@ page import="javax.servlet.http.HttpServlet" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.servlet.http.HttpServletResponse" %>
<%@ page import="com.google.appengine.api.images.Image" %>
<%@ page import="com.google.appengine.api.images.ImagesServiceFactory" %>

<html>
	<head>
		<title>Solve the puzzle!</title>
		<script type="text/javascript">
			//var fullURL = document.URL;
			//var blobKey = fullURL.substring(fullURL.indexOf("blob-key=") + "blob-key=".length, fullURL.length);
			function loadPage() {
				alert("WTF!");
				<%
					BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
					BlobKey blobKey = new BlobKey((String)request.getAttribute("blob-key"));
					byte[] imgarr = blobstoreService.fetchData(blobKey, 0, blobstoreService.MAX_BLOB_FETCH_SIZE-1);
					Image img = ImagesServiceFactory.makeImage(imgarr);
				%>
				document.getElementByID("img").innerHTML = "<%=img.getImageData()%>";
			}
		</script>
	</head>
	<body onload="loadPage()">
		<div id="img"></div>
	</body>
</html>